﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

namespace Extend.Pool
{
    public struct TypeNamePair : IEquatable<TypeNamePair>
    {
        public Type Type { get; }
        public string Name { get; }

        public TypeNamePair(Type type) : this(type, string.Empty) { }

        public TypeNamePair(Type type, string name)
        {
            Type = type;
            Name = name;
        }

        public override string ToString()
        {
            if (Type == null)
            {
                Debug.LogError("TypeNamePair.Type == null");
                return string.Empty;
            }
            return string.IsNullOrEmpty(Name) ? Type.FullName : $"{Type.FullName}_{Name}";
        }

        public override int GetHashCode()
        {
            return Type.GetHashCode() ^ Name.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            return obj is TypeNamePair && Equals((TypeNamePair)obj);
        }

        public bool Equals(TypeNamePair other)
        {
            return Type == other.Type && Name == other.Name;
        }

        public static bool operator ==(TypeNamePair a, TypeNamePair b)
        {
            return a.Equals(b);
        }

        public static bool operator !=(TypeNamePair a, TypeNamePair b)
        {
            return !a.Equals(b);
        }
    }
}
